//
//  UIImage+LZExtension.m
//  百思不得姐
//
//  Created by 郝庆 on 16/5/28.
//  Copyright © 2016年 haoqing. All rights reserved.
//

#import "UIImage+LZExtension.h"

@implementation UIImage (LZExtension)
- (instancetype)lz_circleImage
{
    // 开启图形上下文
    UIGraphicsBeginImageContext(self.size);
    
    // 上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 添加一个圆
    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
    CGContextAddEllipseInRect(ctx, rect);
    
    // 裁剪
    CGContextClip(ctx);
    
    // 绘制图片
    [self drawInRect:rect];
    
    // 获得图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    // 关闭图形上下文
    UIGraphicsEndImageContext();
    
    return image;
}

+ (instancetype)lz_circleImageName:(NSString *)imageName
{
    return [[self imageNamed:imageName] lz_circleImage];
}
@end
